#ifndef _ringbuffer_h
#define _ringbuffer_h
 
#include "linux/types.h"
// #include <limits.h>  // for uint_max
#include "linux/log2.h"
#include "linux/types.h"
#include "linux/slab.h"
#include <linux/uaccess.h>
#include <linux/tty.h>         // tty_insert_flip_char, tty_flip_buffer_push
#include <linux/tty_flip.h>
struct ringbuffer_s {
    uint32_t size;
    uint32_t tail;
    uint32_t head;
    uint8_t * buf; // 这只是开头 从它往后的sz个都是需要的
};
typedef struct ringbuffer_s buffer_t;
 
buffer_t * buffer_new(uint32_t sz);
 
uint32_t buffer_len(buffer_t *r);
 
void buffer_free(buffer_t *r);
 
uint32_t buffer_add(buffer_t *r, const void __user *data, uint32_t sz);
 
uint32_t buffer_remove(buffer_t *r, void __user *data, uint32_t sz);

uint32_t rb_isempty(buffer_t *r);
uint32_t rb_isfull(buffer_t *r);
uint32_t rb_remain(buffer_t *r);
void buffer_report_to_tty(buffer_t *p, struct tty_port *tport, uint32_t sz);
#endif